package cn.doitedu.groovy_test;

import groovy.lang.GroovyClassLoader;

import java.lang.reflect.InvocationTargetException;

public class Demo4 {

    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {

        //String personCode = args[0];

        String code = "package cn.doitedu.demo4;\n" +
                "\n" +
                "public class HelloWorldA implements HelloWorld{\n" +
                "    @Override\n" +
                "    public void sayHello(String name) {\n" +
                "        System.out.println(\"hello \" + name);\n" +
                "    }\n" +
                "}";

        GroovyClassLoader groovyClassLoader = new GroovyClassLoader();

        Class aClass = groovyClassLoader.parseClass(code);

        HelloWorld o = (HelloWorld) aClass.newInstance();
        o.sayHello("zs");

        //Method sayHello = aClass.getMethod("sayHello", String.class);
        //sayHello.invoke(o,"zhangsan");


    }

}
